﻿using Microsoft.Practices.Unity;
using System.Windows;

namespace Arch.Client.IoC
{
    public static class UnityContainerExtentions
    {
        public static IUnityContainer RegisterView<TView, TViewModel>(this IUnityContainer container) where TView : FrameworkElement
        {
            container.RegisterView<TView, TView, TViewModel>();
            return container;
        }

        public static IUnityContainer RegisterView<TViewFrom, TViewTo, TViewModel>(this IUnityContainer container)
            where TViewTo : FrameworkElement, TViewFrom
        {
            container.RegisterType<TViewFrom, TViewTo>(
                new InjectionProperty("DataContext", new ResolvedParameter<TViewModel>())
             );

            return container;
        }
    }
}
